FROM php_base_7.1:latest

#RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories\
#    && apk update \
#    && apk add openssh-client git

ARG X_GID
ARG X_UID

RUN set -eux; \
    if [ -z "`getent group ${X_GID}`" ]; then \
        addgroup -S -g ${X_GID} clonetrooper; \
    fi && \
    adduser -S -D -u ${X_UID} -G `getent group ${X_GID} | cut -d: -f1` clonetrooper \
#    if [ -z "`getent group 2001`" ]; then \
#        addgroup -S -g 2001 clonetrooper; \
#    fi && \
#    adduser -S -D -u 2001 -G `getent group 2001 | cut -d: -f1` clonetrooper \
    && sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
    && apk add --no-cache tzdata \
    && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && rm -rf /var/cache/apk/* \
    && rm -rf /root/.cache \
    && rm -rf /tmp/* \ 
    && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && { \
        echo '[www]'; \
        echo; \
        echo "user = clonetrooper"; \
        echo "group = clonetrooper"; \
    } | tee /usr/local/etc/php-fpm.d/zzz.conf \
    &&  mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" \
    &&  mkdir /run/php  \
    && mkdir -p /data/www/yjs \
    && chown -R clonetrooper:clonetrooper /data

#COPY ./secrets/id_rsa /run/secrets/dx/deploy/
#COPY  ./composer/ /home/clonetrooper/.composer/
#COPY ./conf/.env /data/www/yjs/.env
#COPY --from=nginx_yjs:latest /data/www/yjs/ /data/www/yjs/

## SSH
#        echo 'Host dx.wangcaigu.cn'; \
#        echo '    Hostname dx.wangcaigu.cn'; \
#        echo '    IdentityFile /run/secrets/dx/deploy/id_rsa'; \
#        echo '    IPQoS throughput'; \
#    } | tee /etc/ssh/ssh_config && \
#    chmod 0700 /run/secrets/dx/deploy && \
#    chmod 600 /run/secrets/dx/deploy/id_rsa && \
#    mkdir -p -m 0700 /root/.ssh && \
#RUN    mkdir /run/php && \
#    chown -R clonetrooper:clonetrooper /run &&\
#    git config  --global   http.sslVerify "false"  && \
#    curl -sS https://getcomposer.org/installer | php && \
#    mv composer.phar /usr/local/bin/composer && \
#    chmod +x /usr/local/bin/composer && \
#    mkdir -p -m 0700 /home/clonetrooper/.ssh && \
#    cp /run/secrets/dx/deploy/id_rsa /home/clonetrooper/.ssh && \
#    chown -R clonetrooper:clonetrooper /home/clonetrooper && \
#    #mkdir -p /data/www && \
#    mkdir -p /data/www/yjs && \
#    chown -R clonetrooper:clonetrooper /data
 
WORKDIR /data/www/yjs
#
#RUN cd /data/www/yjs && \
USER clonetrooper

#RUN ssh-keyscan dx.wangcaigu.cn >> /home/clonetrooper/.ssh/known_hosts
#RUN ssh-keyscan dx.wangcaigu.cn >> /home/clonetrooper/.ssh/known_hosts && \
#    git clone ssh://vcs@dx.wangcaigu.cn/source/njfae.git /data/www/yjs && \
##    chown -R clonetrooper:clonetrooper /data && \
##    chown -R clonetrooper:clonetrooper /data 
#    chmod 644 /data/www/yjs/composer.json && \
#    chmod 744 /data/www/yjs/composer.json 
#USER clonetrooper
#WORKDIR /data/www/yjs
#
##RUN   composer install && \
#RUN   mkdir /home/clonetrooper/.composer
#    git clone ssh://vcs@dx.wangcaigu.cn/source/njfae.git /data/www/yjs && \
#    composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/  && \
#RUN   composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ && \
#      composer config -gl && \
#      composer self-update  && \
#      composer diagnose && \
#      composer global require "fxp/composer-asset-plugin:~1.4.5" -vvv 
#    cd /data/www/yjs && \
#    composer global require "fxp/composer-asset-plugin:~1.4.5" -vvv && \
#    composer install -vvv

#COPY ./env/.env /data/www/yjs/.env
#COPY ./conf/ /data/www/yjs/common/config/
#COPY ./conf/frontend /data/www/yjs/frontend/config
#
##    chown -R clonetrooper:clonetrooper /data/www/yjs && \
##    mkdir /run/php && \
##    curl -sS https://getcomposer.org/installer | php && \
##    mv composer.phar /usr/local/bin/composer && \
##    chmod +x /usr/local/bin/composer && \
##    composer install && \
##    composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ && \
##    composer config -gl && \
##    composer global require "fxp/composer-asset-plugin:~1.4.5" -vvv
